package org.clzps.filetransfer.http;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.servlet.ServletFileUpload;


/**
 * Custom ServletFileUpload Class, Override the ServletFileUpload Class
 * @author AriesChou 14/09/2011
 */
@SuppressWarnings({"rawtypes", "unchecked"})
public class CustomServletFileUpload extends ServletFileUpload {
	public CustomServletFileUpload() {
		super();
	}
	
	public CustomServletFileUpload(FileItemFactory fileItemFactory) {
		super(fileItemFactory);
	}
	
	/**
	 * 重载，获取item.isFormField()为false的List集合
	 */
	@Override
	public List parseRequest(HttpServletRequest request)
			throws FileUploadException {
		List tmpList = super.parseRequest(request);
		List rstList = new ArrayList();
		
		Iterator items = tmpList.iterator();
		while(items.hasNext()) {
			FileItem item = (FileItem)items.next();
			if(!item.isFormField()) {
				rstList.add(item);
			}
		}
		return rstList;
	}

}
